﻿

$(function () {
    $('#pp').portal({
        border: false,
        fit: true
    });
    //初始化大框架后，添加portal元素
    add();
    addSystemMessage();
});

function add() {
    $('#tbBaklogTaskList').datagrid({
        url: '/BaklogTask/GetBaklogTaskList',
        iconCls: 'icon-bricks',
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        collapsible: true,
        pagination: true,
        pageList: [15, 20, 50, 100],
        pageSize: 15,
        remoteSort: false,
        idField: 'ID',
        singleSelect: true,
        fitColumns: true,
        columns: [[
                    { title: 'ProcessType', field: 'ProcessType', hidden: true },
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: 'AssociatedFlowCode', field: 'AssociatedFlowCode', hidden: true },
                    { title: 'AssociatedFlowNodeCode', field: 'AssociatedFlowNodeCode', hidden: true },
                    { title: 'AssociatedProcessUserDepartment', field: 'AssociatedProcessUserDepartment', hidden: true },
                    { title: 'AssociatedProcessUser', field: 'AssociatedProcessUser', hidden: true },
                    { title: 'RecordID', field: 'RecordID', hidden: true },
                    {
                        title: '描述', field: 'DisplayText', width: 400,
                        formatter:
                        function (value, row, index) {
                            return '<a href="#" onclick=PopBaklogTaskRequest("' + row.AssociatedFlowCode + '","' + row.ProcessType + '","' + row.ID + '","' + row.AssociatedFlowNodeCode + '","' + row.AssociatedProcessUserDepartment + '","' + row.AssociatedProcessUser + '","' + row.RecordID + '")>' + row.DisplayText + '</a>';
                        }
                    },
                    { title: '时间', field: 'AssociatedDate', width: 150, sortable: true },
        ]]
    });

    $('#tbFlowProcessMessage').datagrid({
        url: '/FlowProcessMessage/GetFlowProcessMessageList',
        iconCls: 'icon-bricks',
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        collapsible: true,
        pagination: true,
        pageList: [15, 20, 50, 100],
        pageSize: 15,
        remoteSort: false,
        idField: 'ID',
        singleSelect: true,
        fitColumns: true,
        columns: [[
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: 'AssociatedFlowCode', field: 'AssociatedFlowCode', hidden: true },
                    { title: 'RecordID', field: 'RecordID', hidden: true },
                    {
                        title: '描述', field: 'DisplayText', width: 400,
                        formatter:
                        function (value, row, index) {
                            return '<a href="#" onclick=PopFlowProcessMessageRequest("' + row.AssociatedFlowCode + '","' + row.RecordID + '")>' + row.DisplayText + '</a>';
                        }
                    },
                    { title: '时间', field: 'AssociatedDate', width: 150, sortable: true },
        ]]
    });

    $('#tbProcessTask').datagrid({
        url: '/ProcessedTask/ProcessedTaskListForProtal',
        iconCls: 'icon-bricks',
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        collapsible: true,
        pagination: true,
        pageList: [15, 20, 50, 100],
        pageSize: 15,
        remoteSort: false,
        idField: 'ID',
        singleSelect: true,
        fitColumns: true,
        columns: [[
                    { title: 'ProcessType', field: 'ProcessType', hidden: true },
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: 'AssociatedFlowCode', field: 'AssociatedFlowCode', hidden: true },
                    { title: 'AssociatedFlowNodeCode', field: 'AssociatedFlowNodeCode', hidden: true },
                    { title: 'AssociatedProcessUserDepartment', field: 'AssociatedProcessUserDepartment', hidden: true },
                    { title: 'AssociatedProcessUser', field: 'AssociatedProcessUser', hidden: true },
                    { title: 'RecordID', field: 'RecordID', hidden: true },
                    {
                        title: '描述', field: 'DisplayText', width: 400,
                        formatter:
                        function (value, row, index) {
                            return '<a href="#" onclick=PopProcessTaskRequest("' + row.AssociatedFlowCode + '","' + row.ProcessType + '","' + row.AssociatedFlowNodeCode + '","' + row.AssociatedProcessUserDepartment + '","' + row.AssociatedProcessUser + '","' + row.RecordID + '")>' + row.DisplayText + '</a>';
                        }
                    },
                    { title: '时间', field: 'AssociatedDate', width: 150, sortable: true },
        ]]
    });
}

function addSystemMessage() {
    $('#tbSystemProcessMessage').datagrid({
        url: '/SystemProcessMessage/GetSystemProcessMessageList',
        iconCls: 'icon-bricks',
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        collapsible: true,
        pagination: true,
        pageList: [15, 20, 50, 100],
        pageSize: 15,
        remoteSort: false,
        idField: 'ID',
        singleSelect: true,
        fitColumns: true,
        columns: [[
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: 'MessageType', field: 'MessageType', hidden: true },
                    { title: 'RecordID', field: 'RecordID', hidden: true },
                    {
                        title: '描述', field: 'Description', width: 400,
                        formatter:
                        function (value, row, index) {
                            return '<a href="#" onclick=PopSystemProcessMessage("' + row.MessageType + '","' + row.RecordID + '","' + row.ID + '")>' + row.Description + '</a>';
                        }
                    },
                    { title: '时间', field: 'SendTimeStr', width: 150, sortable: true },
        ]]
    });

}

function PopBaklogTaskRequest(flowCode, processType, sourceID, flowNodeCode, processUserDepartment, processUser, id) {
    if (flowCode == "AlterOne" || flowCode == "AlterTwo" || flowCode == "AlterThree") {
        showMyWindow("#myWindow", "", "/Alter/Alter?MenuCode=Alter&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&alterID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "AlterOrderOne") {
        showMyWindow("#myWindow", "", "/AlterOrder/AlterOrder?MenuCode=AlterOrder&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&alterOrderID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "Expense") {
        showMyWindow("#myWindow", "", "/Expense/Expense?MenuCode=Expense&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&expenseID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "TotalMaintenance") {
        showMyWindow("#myWindow", "", "/TotalMaintenance/TotalMaintenance?MenuCode=TotalMaintenance&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&totalMaintenanceID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "YearPlan") {
        showMyWindow("#myWindow", "", "/YearPlan/YearPlan?MenuCode=YearPlan&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&yearPlanID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "MonthPlan") {
        showMyWindow("#myWindow", "", "/MonthPlan/MonthPlan?MenuCode=MonthPlan&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&monthPlanID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "StageSchedule") {
        showMyWindow("#myWindow", "", "/StageSchedule/StageSchedule?MenuCode=StageSchedule&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&stageScheduleID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "EngineeringImageSchedule") {
        showMyWindow("#myWindow", "", "/EngineeringImageSchedule/EngineeringImageSchedule?MenuCode=EngineeringImageSchedule&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&engineeringImageScheduleID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "SectionSalary") {
        showMyWindow("#myWindow", "", "/SectionSalary/SectionSalary?MenuCode=SectionSalary&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&sectionSalaryID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "BridgeStatistics") {
        showMyWindow("#myWindow", "", "/BridgeStatistics/Edit?MenuCode=BridgeStatisticsDetail&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&bridgeID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "CulvertStatistics") {
        showMyWindow("#myWindow", "", "/CulvertStatistics/Edit?MenuCode=CulvertStatisticsDetail&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&culvertID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "TunnelStatistics") {
        showMyWindow("#myWindow", "", "/TunnelStatistics/Edit?MenuCode=TunnelStatisticsDetail&sourceType=2&processType=" + processType + "&sourceID=" + sourceID + "&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&tunnelID=" + id, 1000, 500, true, true, true);
    }
}

function PopFlowProcessMessageRequest(flowCode, recordID) {
    if (flowCode == "AlterOne" || flowCode == "AlterTwo" || flowCode == "AlterThree") {
        showMyWindow("#myWindow", "", "/Alter/Alter?MenuCode=Alter&sourceType=4&alterID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "AlterOrderOne") {
        showMyWindow("#myWindow", "", "/AlterOrder/AlterOrder?MenuCode=AlterOrder&sourceType=4&alterOrderID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "Expense") {
        showMyWindow("#myWindow", "", "/Expense/Expense?MenuCode=Expense&sourceType=4&expenseID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "TotalMaintenance") {
        showMyWindow("#myWindow", "", "/TotalMaintenance/TotalMaintenance?MenuCode=TotalMaintenance&sourceType=4&totalMaintenanceID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "YearPlan") {
        showMyWindow("#myWindow", "", "/YearPlan/YearPlan?MenuCode=YearPlan&sourceType=4&yearPlanID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "MonthPlan") {
        showMyWindow("#myWindow", "", "/MonthPlan/MonthPlan?MenuCode=MonthPlan&sourceType=4&monthPlanID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "StageSchedule") {
        showMyWindow("#myWindow", "", "/StageSchedule/StageSchedule?MenuCode=StageSchedule&sourceType=4&stageScheduleID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "EngineeringImageSchedule") {
        showMyWindow("#myWindow", "", "/EngineeringImageSchedule/EngineeringImageSchedule?MenuCode=EngineeringImageSchedule&sourceType=4&engineeringImageScheduleID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "SectionSalary") {
        showMyWindow("#myWindow", "", "/SectionSalary/SectionSalary?MenuCode=SectionSalary&sourceType=4&sectionSalaryID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "BridgeStatistics") {
        showMyWindow("#myWindow", "", "/BridgeStatistics/Edit?MenuCode=BridgeStatisticsDetail&sourceType=4&bridgeID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "CulvertStatistics") {
        showMyWindow("#myWindow", "", "/CulvertStatistics/Edit?MenuCode=CulvertStatisticsDetail&sourceType=4&culvertID=" + recordID, 1000, 500, true, true, true);
    }
    else if (flowCode == "TunnelStatistics") {
        showMyWindow("#myWindow", "", "/TunnelStatistics/Edit?MenuCode=TunnelStatisticsDetail&sourceType=4&tunnelID=" + recordID, 1000, 500, true, true, true);
    }
}

function PopProcessTaskRequest(flowCode, processType, flowNodeCode, processUserDepartment, processUser, id) {
    if (flowCode == "AlterOne" || flowCode == "AlterTwo" || flowCode == "AlterThree") {
        showMyWindow("#myWindow", "", "/Alter/Alter?MenuCode=Alter&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&alterID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "AlterOrderOne") {
        showMyWindow("#myWindow", "", "/AlterOrder/AlterOrder?MenuCode=AlterOrder&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&alterOrderID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "Expense") {
        showMyWindow("#myWindow", "", "/Expense/Expense?MenuCode=Expense&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&expenseID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "TotalMaintenance") {
        showMyWindow("#myWindow", "", "/TotalMaintenance/TotalMaintenance?MenuCode=TotalMaintenance&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&totalMaintenanceID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "YearPlan") {
        showMyWindow("#myWindow", "", "/YearPlan/YearPlan?MenuCode=YearPlan&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&yearPlanID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "MonthPlan") {
        showMyWindow("#myWindow", "", "/MonthPlan/MonthPlan?MenuCode=MonthPlan&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&monthPlanID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "StageSchedule") {
        showMyWindow("#myWindow", "", "/StageSchedule/StageSchedule?MenuCode=StageSchedule&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&stageScheduleID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "EngineeringImageSchedule") {
        showMyWindow("#myWindow", "", "/EngineeringImageSchedule/EngineeringImageSchedule?MenuCode=EngineeringImageSchedule&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&engineeringImageScheduleID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "SectionSalary") {
        showMyWindow("#myWindow", "", "/SectionSalary/SectionSalary?MenuCode=SectionSalary&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&sectionSalaryID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "BridgeStatistics") {
        showMyWindow("#myWindow", "", "/BridgeStatistics/Edit?MenuCode=BridgeStatisticsDetail&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&bridgeID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "CulvertStatistics") {
        showMyWindow("#myWindow", "", "/CulvertStatistics/Edit?MenuCode=CulvertStatisticsDetail&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&culvertID=" + id, 1000, 500, true, true, true);
    }
    else if (flowCode == "TunnelStatistics") {
        showMyWindow("#myWindow", "", "/TunnelStatistics/Edit?MenuCode=TunnelStatisticsDetail&sourceType=3&processType=" + processType + "&sourceID=&associatedNodeCode=" + flowNodeCode + "&lastUpdateUserDepartment=" + processUserDepartment + "&lastUpdateUser=" + processUser + "&tunnelID=" + id, 1000, 500, true, true, true);
    }
}

function PopSystemProcessMessage(messageType, recordID, id) {
    $.post("/SystemProcessMessage/DeleteSystemProcessMessage?id=" + id, function (res) {
        if (res == "Success") {
            $("#tbSystemProcessMessage").datagrid("reload");
        }
        else {
            return;
        }
    });

    if (messageType == "QualityCircular") {
        PreviewMutual("/QualityCircular/Preview?id=" + recordID);
    }
    else if (messageType == "SafetyCircular") {
        PreviewMutual("/Circular/Preview?id=" + recordID);
    }
}

function PreviewMutual(href) {
    $.ModelDialog({
        title: "预览", href: href, width: 535,
        onLoad: function () { }
    });
}

function CloseWindow(data) {
    colseMyWindow("#myWindow");
    add();
    $.EasyuiSlide(data);
}

function cancelPopWindow() {
    colseMyWindow("#myWindow");
}